package cn.wolfcode.p2p.base.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;

@Getter@Setter
public class RealAuth extends BaseAudit{
    public static final int SEX_MALE=0;
    public static final int SEX_FEMALE=1;
    private String realname;//真实姓名
    private Integer sex=SEX_MALE;//性别
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date bornDate;//出生日期
    private String idNumber;//身份证
    private String address;//住址
    private String image1;//阵面
    private String image2;//反面
    public String getSexName(){
        return sex==SEX_MALE?"男":"女";
    }

    public String getJsonString(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("realname",realname);
        map.put("id",id);
        map.put("username",getApplier().getUsername());
        map.put("idNumber",idNumber);
        map.put("sex",getSexName());
        map.put("address",address);
        map.put("image1",image1);
        map.put("image2",image2);
        map.put("bornDate", DateFormat.getDateInstance().format(bornDate));
        try {
            return new ObjectMapper().writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

}